package com.future.controller;

import com.future.domain.Result;
import com.future.service.ChatMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "聊天室成员管理")
public class ChatMemberController {
    @Autowired
    private ChatMemberService memberService;
    /**
     * 获取聊天室成员列表
     * @param roomId 聊天室ID
     * @return 成员列表(包含在线状态)
     */
    @GetMapping("/room-members")
    @ApiOperation("获取聊天室成员列表")
    public Result getRoomMembers(@RequestParam String roomId) {
        return memberService.getRoomMembers(roomId);
    }
    /**
     * 向聊天室添加成员(仅群主可操作)
     * @param roomId 聊天室ID
     * @param userIds 用户ID列表
     * @return 操作结果
     */
    @PostMapping("/add-members/{roomId}")
    @ApiOperation("向聊天室添加成员")
    public Result addRoomMember(@PathVariable("roomId") String roomId, @RequestBody List<String> userIds) {
        return memberService.addRoomMember(roomId, userIds);
    }
    /**
     * 获取用户在线状态
     * @return 在线状态(0:离线,1:在线,-1:用户不存在)
     */
    @GetMapping("/online-status")
    @ApiOperation("获取用户在线状态")
    public Result getUserOnlineStatus() {
        return memberService.getUserOnlineStatus();
    }
    /**
     * 根据用户名查询用户
     */
    @PostMapping("/selectUserbyname")
    public Result selectUserbyname(String name)
    {
        return memberService.selectByusername(name);
    }
    @GetMapping("/getUnjoin")
    @ApiOperation("获取未加入群聊的用户列表")
    public Result getUnjoin(
                            @RequestParam("pageNum")Integer pageNum,
                            @RequestParam("pageSize")Integer pageSize)
    {
        return memberService.unJoinChatRoom(pageNum,pageSize);
    }
    @GetMapping("/getChatMemberCount")
    @ApiOperation("获取聊天室成员数")
    public Result getCount(@RequestParam("roomId")String roomId)
    {
        return memberService.memberCount(roomId);
    }
    @DeleteMapping("/deleteRoom")
    @ApiOperation("删除私信/心理咨询")
    public Result delectRoom(@RequestParam("roomId")String roomId)
    {
       return memberService.delectChatRoom(roomId);
    }
}

